package com.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by pengfei on 2017/7/24.
 */
@WebServlet(name="userservlet",
            urlPatterns="/userservlet",
            loadOnStartup=1,
            initParams={
                @WebInitParam(name="username",value="张三")
            }
        )
public class TestServlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        //获取初始值username
        System.out.println(config.getInitParameter("username"));
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("doget方法执行");
    }
}
